import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalPush.call(this, location, onResolve, onReject)
  }
  return originalPush.call(this, location).catch(err => err)
}

/**
 * Note: 路由配置项
 *
 * hidden: true                   // 当设置 true 的时候该路由不会在侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true               // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect           // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'             // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * meta : {
    noCache: true                // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'               // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'             // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false            // 如果设置为false，则不会在breadcrumb面包屑中显示
  }
 */

// 公共路由
export const constantRoutes = [{
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: resolve => require(['@/views/redirect'], resolve)
    }]
  },
  {
    path: '/login',
    component: resolve => require(['@/views/login'], resolve),
    hidden: true
  },
  {
    path: '/oauthLogin',
    component: resolve => require(['@/views/oauthLogin'], resolve),
    hidden: true
  },
  {
    path: '/504',
    component: resolve => require(['@/views/error/504'], resolve),
    hidden: true
  }, {
    path: '/502',
    component: resolve => require(['@/views/error/502'], resolve),
    hidden: true
  },
  {
    path: '/404',
    component: resolve => require(['@/views/error/404'], resolve),
    hidden: true
  },
  {
    path: '/401',
    component: resolve => require(['@/views/error/401'], resolve),
    hidden: true
  },
  {
    path: '/notAccessPer401',
    component: resolve => require(['@/views/error/notAccessPer401'], resolve),
    hidden: true
  },
  {
    path: '/replacementTips',
    component: resolve => require(['@/views/error/replacementTips'], resolve),
    hidden: true
  },
  {
    path: '/attachment/upload',
    component: resolve => require(['@/views/attachment/upload'], resolve),
    hidden: true
  },
  {
    path: '/attachment/pdf',
    component: resolve => require(['@/views/attachment/pdf'], resolve),
    hidden: true
  },
  {
    path: '/smartform/render',
    component: resolve =>
      require(['@/views/smartform/smartForm/render'], resolve),
    hidden: true
  },
  {
    path: '/smartform/viewRender',
    component: resolve =>
      require(['@/views/smartform/smartForm/viewRender'], resolve),
    hidden: true
  },
  // smartform 工作流页面预览
  {
    path: '/smartform/workflowRender',
    component: resolve =>
      require(['@/views/smartform/smartForm/workflow'], resolve),
    hidden: true
  },
  {
    path: '/smartform/mobileRender',
    component: resolve =>
      require(['@/views/smartform/smartForm/mobileRender'], resolve),
    hidden: true
  },
  {
    path: '/workflow/demoLeaveApply/create',
    component: resolve =>
      require(['@/views/workflow/demoLeaveApply/create'], resolve),
    hidden: true
  },
  {
    path: '/workflow/kpi/create',
    component: resolve =>
      require(['@/views/workflow/kpi/create'], resolve),
    hidden: true
  },
  {
    path: '/report/list',
    component: resolve =>
      require(['@/views/report/list'], resolve),
    hidden: true
  },
  {
    path: '/report/view/:id',
    component: resolve =>
      require(['@/views/report/view'], resolve),
    hidden: true
  },
  {
    path: '/report/shareView/:id',
    component: resolve =>
      require(['@/views/report/shareView'], resolve),
    hidden: true
  },
  {
    path: '/report/index/:id/:menuType',
    component: resolve =>
      require(['@/views/report/index'], resolve),
    hidden: true
  },
  {
    path: '/report/index/:id',
    component: resolve =>
      require(['@/views/report/index'], resolve),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: '/index',
    children: [{
      path: '/index',
      component: resolve => require(['@/views/index'], resolve),
      name: 'Index',
      meta: {
        title: '首页',
        icon: 'dashboard',
        noCache: true,
        affix: true
      }
    }, {
      path: '/admin/readNotice/list',
      name: 'ReadNotice',
      component: resolve =>
        require(['@/views/admin/readNotice/list'], resolve),
      hidden: true,
      meta: {
        title: '通知公告',
      }
    }]
  },
  // eip项目静态路由配置
  {
    path: '/eip/ClientView',
    name: 'ClientView',
    component: resolve =>
      require(['@/views/eip/clientView'], resolve),
    hidden: true
  },
  {
    path: '/eip/ChanceView',
    name: 'ChanceView',
    component: resolve =>
      require(['@/views/eip/chanceView'], resolve),
    hidden: true
  },
  {
    path: '/eip/ContractView',
    name: 'ContractView',
    component: resolve =>
      require(['@/views/eip/contractView'], resolve),
    hidden: true
  },
  {
    path: '/admin/calendar/taskList',
    name: 'TaskListView',
    component: resolve =>
      require(['@/views/admin/calendar/taskList'], resolve),
    hidden: true
  },
  {
    path: '/eip/ProjectView',
    name: 'ProjectView',
    component: resolve =>
      require(['@/views/eip/projectView'], resolve),
    hidden: true
  },
  // bi项目静态路由配置
  {
    path: '/portal/View',
    name: 'PortalView',
    component: resolve =>
      require(['@/views/bi/portal/PortalView'], resolve),
    hidden: true
  },
  {
    path: '/portal/Customiz',
    name: 'PortalCustomiz',
    component: resolve =>
      require(['@/views/bi/portal/PortalCustomiz'], resolve),
    hidden: true
  },

  {
    path: '/bireport/Print',
    name: 'bireportPrint',
    component: resolve =>
      require(['@/views/bi/bireport/Print'], resolve),
    hidden: true
  },
  {
    path: '/portal/Print',
    name: 'portalPrint',
    component: resolve =>
      require(['@/views/bi/portal/Print'], resolve),
    hidden: true
  },
  {
    path: '/portal/ShareView',
    name: 'portalShareView',
    component: resolve =>
      require(['@/views/bi/portal/PortalShareView'], resolve),
    hidden: true
  }
]

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})
